package com.company.project.web;
import com.company.project.api.IOrderApi;
import com.company.project.core.Result;
import com.company.project.core.ResultGenerator;
import com.company.project.model.TradeOrder;
import com.company.project.service.TradeOrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by CodeGenerator on 2018/12/07.
*/

public abstract class TradeOrderController implements IOrderApi{
    @Resource
    public TradeOrderService tradeOrderService;
    @ApiIgnore
    @PostMapping("/add")
    public Result add(TradeOrder tradeOrder) {
        tradeOrderService.save(tradeOrder);
        return ResultGenerator.genSuccessResult();
    }
    @ApiIgnore
    @PostMapping("/delete")
    public Result delete(@RequestParam Integer id) {
        tradeOrderService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }
    @ApiIgnore
    @PostMapping("/update")
    public Result update(TradeOrder tradeOrder) {
        tradeOrderService.update(tradeOrder);
        return ResultGenerator.genSuccessResult();
    }
    @ApiIgnore
    @PostMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        TradeOrder tradeOrder = tradeOrderService.findById(id);
        return ResultGenerator.genSuccessResult(tradeOrder);
    }
    @ApiIgnore
    @PostMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<TradeOrder> list = tradeOrderService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
}
